<template>
	<view class="content">
		<view class="dis_sb ml20 mr20 line26 mb20 pl20 bgfff">
			<view class="dis_sc">
				<view>日期选择：</view>
				<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
					<view class="">{{date}}</view>
				</picker>				
			</view>
			<button class="bgblue  line18 clo-fff f28 pl20 pr20 mr20" @click="searchdata">查询</button>
		</view>

		<view class="main" v-if="list.length > 0">
			<view v-for="(item,index) in list" class=" dis_sb bgfff pt10 pb10 ml20 mr20 mb20 pl20 pr20 line18">
				<view class="w100">
					<view>{{item.po_order_sn}}</view>
					<view>{{item.po_user_name}}</view>
					<view class="clo-999 f24">收益时间：{{item.re_create}}</view>
				</view>
				<view class="clo-blue tac w30 shrink"><view>收益(元)</view>	<text class="f34 fwb">{{item.po_fenxiao_money}}</text></view>
			</view>
		</view>
		<div class="listdata_desc" v-if="list.length > 0 && listdata_desc != ''">{{ listdata_desc }}</div>
		<template v-if="list.length == 0">
		    <div class="empty_box acea-row row-center-wrapper">
		        <div>
		            <div class="empty_icon">
		                <image class="img" src="/static/icon_null.png" mode="aspectFill"></image>
		            </div>
		            <div class="empty_msg">暂无数据</div>
		        </div>
		    </div>
		</template>
	</view>
</template>

<script>
	import {incomeIndex} from '@/utils/api.js'
	export default {
		data() {
			const currentDate = this.getDate({
			    format: true
			})
			return {
				date: '点击选择日期筛选',
				is_more:true,
				listdata_desc:'',
				list:[],
				searchFrom: {
					dates: '',
					page: 1,
					pageSize: 20
				}
			}
		},
		computed: {
			startDate() {
				return this.getDate('start');
			},
			endDate() {
				return this.getDate('end');
			}
		},
		//监听滑动到底部
		onReachBottom() {
			if (this.is_more) {
			    this.searchFrom.page++;
			    this.get_list();
			}
		},
		onLoad() {
			this.get_list();
		},
		methods: {
			searchdata(){
				if(this.date == '点击选择日期筛选'){
					this.searchFrom.dates = '';
				}else{
					this.searchFrom.dates = this.date;
				}

				this.searchFrom.page = 1;
				this.is_more = true;
				this.list = [];
				this.get_list();
			},
			get_list(){
				this.listdata_desc = '正在加载';
				incomeIndex(this.searchFrom).then(res=>{
					let list = res.data.list
					if(this.page == 1){
					    this.is_more = true;
					    this.list = [];
					}
					
					this.listdata_desc = '';
					if (list.length == 0) {
					    //阻止继续分页
					    this.is_more = false;
					    this.listdata_desc = '没有更多了';
					    return;
					}
					if (list.length < this.pageSize) {
					    this.is_more = false;
					    this.listdata_desc = '没有更多了';
					}
					if(list.length > 0){
						list.forEach(item=>{
							this.list.push(item)
						})
					}
				})
			},
			bindDateChange: function(e) {
			    this.date = e.detail.value
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			}
		}
	}
</script>

<style>
	
	.content {background: linear-gradient(#3172f9 10%, #f8f8f8); padding-top: 20rpx; min-height: 100%;}
	
	.main {height: 87vh; overflow-y: auto;}
</style>
